package com.stars.empoly.adapter

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.R
import com.stars.empoly.databinding.ItemModelBinding
import com.yanzhenjie.permission.AndPermission
import com.yanzhenjie.permission.runtime.Permission
import com.trailer.base.base.BAdapter
import com.trailer.base.ccretrofit.CCRetrofit
import com.trailer.base.route.ILookimg
import java.util.*

class ModelAdapter(var list: ArrayList<String>) : BAdapter<String, BaseDataBindingHolder<ItemModelBinding>>(R.layout.item_model) {

    override fun convert(holder: BaseDataBindingHolder<ItemModelBinding>, item: String) {
        holder.dataBinding?.item = item

        holder.dataBinding?.imgAttachment?.onClick {
            //查看大图


            AndPermission.with(context)
                    .runtime()
                    .permission(
                            Permission.WRITE_EXTERNAL_STORAGE,
                            Permission.READ_EXTERNAL_STORAGE
                    )
                    .onGranted { data ->
                        CCRetrofit.instance()
                                .create(ILookimg::class.java)
                                .previewImageArr(list,holder.adapterPosition)
                                .subscribe()
                    }
                    .start()

        }
    }
}
